import { RouteRecordRaw, createRouter, createWebHistory } from 'vue-router'

import { systemRouter } from './system'
import { designRouter } from './design'
import { previewRouter } from './preview'
import { oidcRouter } from '@/tools/oidc/router'

const routerData: Array<RouteRecordRaw> = [
  {
    path: '/',
    name: '/',
    redirect: './home',
    children: [...oidcRouter, ...systemRouter],
    meta: {
      isPublic: true,
      isOidcCallback: true,
    },
  },
  ...designRouter,
  ...previewRouter,
]

/**
 * 创建路由
 */
const router = createRouter({
  history: createWebHistory(import.meta.env.VITE_PUBLIC_PATH),
  routes: routerData,
  // 刷新时，滚动条位置还原
  scrollBehavior: () => ({ left: 0, top: 0 }),
})

export default router
